package com.baosight.risk.service.zbaa.impl;

import com.baosight.risk.api.zbaa.IZbaaTargetService;
import com.baosight.risk.api.zbaa.IZbaaTargetValueService;
import com.baosight.risk.base.service.BaseServiceImpl;
import com.baosight.risk.common.bean.BeanUtils;
import com.baosight.risk.mapper.zbaa.ZbaaTargetValueMapper;
import com.baosight.risk.service.zbaa.entity.ZbaaTarget;
import com.baosight.risk.service.zbaa.entity.ZbaaTargetValue;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class ZbaaTargetValueServiceImpl extends BaseServiceImpl<ZbaaTargetValue> implements IZbaaTargetValueService {

    @Autowired
    ZbaaTargetValueMapper zbaaTargetValueMapper;

    @Autowired
    private IZbaaTargetService targetService;

    @Override
    public Integer insertValueList(List<ZbaaTargetValue> list) {
        for (ZbaaTargetValue zbaaTargetValue : list) {
            int insert = zbaaTargetValueMapper.insert(zbaaTargetValue);
            if (insert < 1) {
                return -1;
            }
        }
        return 1;
//        Integer result = zbaaTargetValueMapper.insertValueList(list);
//        return result;
    }

    @Override
    public List<ZbaaTargetValue> selectBsteelTargetValue(ZbaaTargetValue targetValue) {
        return zbaaTargetValueMapper.selectBsteelTargetValue(targetValue);
    }

    @Override
    public Integer deleteValueByBsteel(ZbaaTargetValue targetValue) {
        return zbaaTargetValueMapper.deleteValueByBsteel(targetValue);
    }

    @Override
    public void test() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                List<ZbaaTarget> targets = targetService.selectAll();

                Map<String, ZbaaTarget> targetMap = new HashMap<>();

                for (ZbaaTarget target : targets) {
                    targetMap.put(target.getTargetNo(), target);
                }
                int index = 0;
                List<ZbaaTargetValue> targetValues = zbaaTargetValueMapper.getAll();
                for (ZbaaTargetValue targetValue : targetValues) {
                    ZbaaTarget target = targetMap.get(targetValue.getTargetNo());
                    if (target != null) {
                        targetValue.setTargetType(target.getTargetType());
                        targetValue.setTargetTypeName(target.getTargetTypeName());
                        targetValue.setTargetPeriod(target.getTargetPeriod());
                        targetValue.setTargetPeriodName(target.getTargetPeriodName());
                        targetValue.setSysSource(target.getSysSource());
                        targetValue.setSysSourceName(target.getSysSourceName());
                        targetValue.setRangeCode(target.getRangeCode());
                        targetValue.setRangeName(target.getRangeName());
                        targetValue.setQuantityFlag(target.getQuantityFlag());
                        targetValue.setQuantityFlagC(target.getQuantityFlagC());
                        targetValue.setUnit(target.getUnit());
                        targetValue.setCompCode(target.getCompCode());
                        targetValue.setCompName(target.getCompName());
                        targetValue.setDdTypeCode(target.getDdTypeCode());
                        targetValue.setDdTypeName(target.getDdTypeName());
                        targetValue.setSourceTargetNo(target.getSourceTargetNo());
                        targetValue.setRiskSource(target.getRiskSource());
                        targetValue.setRiskSourceName(target.getRiskSourceName());
                        zbaaTargetValueMapper.updateByPrimaryKeySelective(targetValue);
                        index ++;
                        System.out.println("已处理----" +index);
                    }
                }
                System.out.println("处理完毕");
            }
        }).start();

    }

}
